<?php

class Users extends MY_Controller {
	var $currentPage = 'users';
	var $caption = 'User';
	var $acion = '';
	
	public function index()
	{
		
	//$this->user is autoload at Controller's constructor
	   $test = $this->user->limit(1,10);
	   $data['userList'] = $this->user->getAllEntries();
	   //$this->loadAdminPage($data);
	   
	   $this->loadClientPage($data);
	}
	
	public function create(){
		$data = '';
	//	$data['teamList'] = $this->team->getAllEntries();
		$this->action = 'add';
		$this->loadAdminPage($data);
	}
	
	public function edit($id){
		//$data = '';
		$this->action = 'edit';
		//$this->user is autoload at Controller's constructor
		$data =  $this->user->getEntryById($id);
	    $data['teamList'] = $this->team->getAllEntries();
		$this->loadAdminPage($data);
	}
	
	 function save(){
    	//create a reference
    	$user = &$this->user;
    	$this->setValues($user);
    	
    	if(! isset($_REQUEST['id']) || $_REQUEST['id'] == ''){
    		$user->insert();
    		$this->edit($this->db->insert_id()); 
    	}else{
    		$user->id = $_REQUEST['id'];
    		$user->update();
    		$this->edit($_REQUEST['id']); 
    	}
    	
    }
    
	
	
	function setValues($user){
    	
        $user->surname   = $_REQUEST['surname']; 
        $user->firstname = $_REQUEST['firstname'];
        $user->maidenname  =  $_REQUEST['maidenname'];
    	$user->usertype   = $_REQUEST['usertype']; 
        $user->status = $_REQUEST['status'];
        $user->staffcode  =  $_REQUEST['staffcode'];
        $user->email   = $_REQUEST['email']; 
        $user->username = $_REQUEST['username'];
        $user->password  =  $_REQUEST['password'];
        $user->team = $_REQUEST['team'];
    	
    }
    
	
	public function delete($id){
		$this->user->delete($id);
		$this->index();
	}
	
	
}